﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

public class Request_Login : RequestBase
{
    public const string NetRequest_Login_Key = "Login";
    
    public LoginRequestData loginReqData = new LoginRequestData();

    protected override ISerialize requestData
    {
        get
        {
            return loginReqData;
        }
    }

    public Request_Login() : base()
    {
        MessagePacket.key = NetRequest_Login_Key;
    }

    public static LoginRequestData GetDefaultData()
    {
         var loginReqData = new LoginRequestData();
         loginReqData.langType = Localization.language.ToString();
         loginReqData.os = UnityEngine.SystemInfo.operatingSystem;
         loginReqData.cpu = UnityEngine.SystemInfo.processorType;
         loginReqData.deviceName = UnityEngine.SystemInfo.deviceName;
         loginReqData.deviceModel = UnityEngine.SystemInfo.deviceModel;
         loginReqData.appBuild = AppBuildInfo.buildNumber;
         loginReqData.appVersion = AppBuildInfo.appVersion;
         loginReqData.g_Name = SystemInfo.graphicsDeviceName;
         loginReqData.g_Vendor = SystemInfo.graphicsDeviceVendor;
         loginReqData.g_Version = SystemInfo.graphicsDeviceVersion;
         loginReqData.platform = (int)Application.platform;//iphone 8, android 11
         loginReqData.loginType = GetLoginType();
         return loginReqData;
    }


    public const int LoginType_Editor = -1;
    public const int LoginType_GooglePlay = 0;
    public const int LoginType_UDP = 1;
    public const int LoginType_AppStore = 2;
    
    public static int GetLoginType()
    {
 #if UNITY_EDITOR
        return LoginType_Editor;
#endif
#if UNITY_ANDROID
        return LoginType_GooglePlay;
#endif
#if UNITY_IOS
        return LoginType_AppStore;
#endif
        return LoginType_Editor;
    }

    public override void OnSend()
    {
        base.OnSend();

       GameDebug.Log($"发送登录请求：{loginReqData.uuid}");
    }

    public override ResponseData NewResponseData() => new LoginResponseData();

    //public override ResponseBase GetResponseHandler()
    //{
    //    return new Response_Login();
    //}


}


//public class Response_Login : ResponseBase
//{
//    public LoginResponseData loginResponseData => this.responseData as LoginResponseData;

//    public User user => this.loginResponseData.user;
//    public LastBattleConnectInfo LastBattleConnectInfo => this.loginResponseData.lastBattleConnectInfo;
//    //public ConstData constData => this.responseData.constData;
//    //public LoginBonusData loginBonusData => this.responseData.loginBonusData;

//    public override ResponseData NewResponseData() => new LoginResponseData();
        
    

//    public override void Excuate()
//    {
//        //GameDebug.LogShowy("Response_Login -> Excuate");
        
//        var loginRequest = this.request as Request_Login;

//        //Game.Instance.user = this.user;

//        if (loginRequest.onResponse != null)
//            loginRequest.onResponse(this);
//    }
//}